<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>所有品牌</title>
    <style>
        table {
            border-collapse: collapse;
        }

        tr {
            height: 30px;
            text-align: center;
        }

        tr:hover {
            background-color: lightgoldenrodyellow;
        }

        td {
            padding: 2px;
        }
    </style>
</head>
<body>

<input type="button" value="新增" onclick="location.href='addBrand.jsp';">

欢迎您！${user.username}

<hr>

<table border="1" cellspacing="0">
    <tr style="background-color: lightcyan">
        <th>序号</th>
        <th>品牌名称</th>
        <th>企业名称</th>
        <th>排序</th>
        <th>品牌介绍</th>
        <th>状态</th>
        <th>操作</th>
    </tr>

    <c:forEach items="${brands}" var="brand" varStatus="row">
    <tr align="center">
        <td>${row.count}</td>
        <td>${brand.brandName}</td>
        <td>${brand.companyName}</td>
        <td>${brand.ordered}</td>
        <td style="text-align: left;" width="350">${brand.description}</td>
        <td>${brand.status==0?"禁用":"启用"}</td>
        <td><a href="selectById?id=${brand.id}">修改</a>
            <a href="javascript:deleteBrand('${brand.id}','${brand.brandName}')">删除</a>
        </td>
    </tr>
    </c:forEach>

</table>

<script type="text/javascript">
    /**
     * 删除一行
     * @param id 要删除的主键
     */
    function deleteBrand(id,brandName) {
        //在JSP中EL表达式与JS中插值运算有冲突，可以在$前面加\转义，让EL不起作用
        if (confirm("真的要删除" + brandName + "这一行吗?")) {
            //跳到删除的servlet中
            location.href = `deleteServlet?id=\${id}`;
        }
    }
</script>
</body>
</html>
